package com.wangcang.widgetlibrary.activity;

import android.animation.ValueAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.progressbar.CircleProgressView;
import com.wangcang.widgetlibrary.progressbar.HorizontalProgressView;

public class ProgressbarActivity extends AppCompatActivity {

	private Button mBtnStart;
	private CircleProgressView mCircleProgressView;
	private CircleProgressView mCpvDesc;
	private CircleProgressView mCpvNoBackground;
	private HorizontalProgressView mHpvFollow;
	private HorizontalProgressView mHpvRight;
	private HorizontalProgressView mHpvRightTop;
	private Button mBtnStartHpv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_progressbar);
		mBtnStart = (Button) findViewById(R.id.btn_start);
		mCircleProgressView = (CircleProgressView) findViewById(R.id.circle_process_view);
		mCpvDesc = (CircleProgressView) findViewById(R.id.cpv_desc);
		mCpvNoBackground = (CircleProgressView) findViewById(R.id.cpv_no);
		mHpvFollow = (HorizontalProgressView) findViewById(R.id.hpv_follow);
		mHpvRight = (HorizontalProgressView) findViewById(R.id.hpv_right);
		mHpvRightTop = (HorizontalProgressView) findViewById(R.id.hpv_right_top);
		mBtnStartHpv = (Button) findViewById(R.id.btn_start2);
		final ValueAnimator circleAnimator = ValueAnimator.ofInt(0, mCircleProgressView.getProgress());
		circleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

			@Override
			public void onAnimationUpdate(ValueAnimator animator) {
				//获得当前动画的进度值，整型，1-100之间
				int currentValue = (Integer) animator.getAnimatedValue();
				mCircleProgressView.setProgress(currentValue);
				mCpvDesc.setProgress(currentValue);
				mCpvNoBackground.setProgress(currentValue);
			}
		});
		circleAnimator.setDuration(1000);

		final ValueAnimator hpvAnimator = ValueAnimator.ofInt(0, mHpvFollow.getProgress());
		hpvAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

			@Override
			public void onAnimationUpdate(ValueAnimator animator) {
				//获得当前动画的进度值，整型，1-100之间
				int currentValue = (Integer) animator.getAnimatedValue();
				mHpvFollow.setProgress(currentValue);
				mHpvRight.setProgress(currentValue);
				mHpvRightTop.setProgress(currentValue);
			}
		});
		hpvAnimator.setDuration(1000);

		mBtnStartHpv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				hpvAnimator.start();
				mHpvRight.setProgressAndTextColor(Color.RED);
			}
		});

		mBtnStart.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

				circleAnimator.start();
			}
		});
	}
}
